package view.GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.*;
import model.graphic.GraphicModel;
import view.GUI.graphic.SkinReader;

/**
 *
 * @author Ben
 */
public class SkinChooser extends JDialog implements ActionListener {
    private JComboBox cmbSkins;
    private JButton btnOK;
    private JButton btnCancel;
    private GraphicModel graphicModel;
    private JScrollPane scroll;

    public SkinChooser(GraphicModel graphicModel, JScrollPane scroll) {
          this.graphicModel = graphicModel;
          this.scroll = scroll;
          setLocationRelativeTo(null);
          File skinRoot = new File(SkinReader.getSkinPath());
	  cmbSkins = new JComboBox(skinRoot.list());

          btnOK = new JButton(LabelReader.getInstance().getString("ApplySkin"));
          btnOK.setActionCommand("OK");
          btnOK.addActionListener(this);

          btnCancel = new JButton(LabelReader.getInstance().getString("Cancel"));
          btnCancel.setActionCommand("Cancel");
          btnCancel.addActionListener(this);

          JPanel panel = new JPanel();
          panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
          panel.add(cmbSkins);
          panel.add(btnOK);
          panel.add(btnCancel);
          this.setTitle(LabelReader.getInstance().getString("ChooseASkin"));
          this.setContentPane(panel);
          pack();
          this.setVisible(true);
    }

    public void actionPerformed(ActionEvent ae) {
        if(ae.getActionCommand().equals("OK")){
            try{
                SkinReader.getInstance().setSkin((String)cmbSkins.getSelectedItem());
                scroll.repaint();
            }catch(Exception ex){
                JOptionPane.showMessageDialog(null,"SkinChooser:" + ex.getMessage(),
                 LabelReader.getInstance().getString("Error") ,
                 JOptionPane.ERROR_MESSAGE);
            }
            this.dispose();
        }else if(ae.getActionCommand().equals("Cancel")){
            this.dispose();
        }
    }

}
